package com.xp.code.servicesImpl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xp.code.dao.IUnitInfoDao;
import com.xp.code.services.IUnitInfoService;
import com.xp.code.vo.UnitInfoVO;

/**
 * 
 * @author HAHA
 *
 */
@Service("unitInfoService")
@Transactional(rollbackFor=java.lang.Exception.class)
public class UnitInfoService implements IUnitInfoService {

	@Resource(name="unitInfoDao")
	private IUnitInfoDao unitInfoDao;
	
	public UnitInfoService() {
		
	}

	public IUnitInfoDao getUnitInfoDao() {
		return unitInfoDao;
	}

	public void setUnitInfoDao(IUnitInfoDao unitInfoDao) {
		this.unitInfoDao = unitInfoDao;
	}
	
	public UnitInfoVO addUnitInfos(UnitInfoVO unitInfoVO)throws Exception{
		return unitInfoDao.addUnitInfos(unitInfoVO);
	}
	
	public List<UnitInfoVO> getParentUnitInfo(String unitID)throws Exception{
		UnitInfoVO vo=null;
		List<UnitInfoVO> lists=new ArrayList<UnitInfoVO>();
		List<Object[]> list=unitInfoDao.getParentUnitInfo(unitID);
		for(Object[] obj:list){
			vo=new UnitInfoVO();
			vo.setId(obj[0].toString());
			vo.setVarname(obj[1].toString());
			vo.setVarcode(obj[2].toString());
			lists.add(vo);
		}
		return lists;
	}
}
